<!DOCTYPE html>
<html>

<head>
    <title>员工主页·车队管理系统</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <!-- import CSS -->
    <link rel="stylesheet" href="/static/css/vant.css">
    <link rel="stylesheet" href="/static/css/StartAdmin.css">

</head>

<body>
<div id="app">
    <van-row>
        <van-nav-bar title="我的信息"/>
    </van-row>

    <van-row type="flex" justify="center">
        <img src="/static/images/logo.png" width="80px" height="80px">
    </van-row>
    <van-divider
            :style="{ color: '#1989fa', borderColor: '#1989fa', padding: '0 16px' }"
    >
        {{user.name}}
    </van-divider>
    <van-row><van-divider>修改密码</van-divider></van-row>
    <van-form @submit="onSubmit">
        <van-field
                v-model="form.oldpswd"
                type="password"
                name="原密码"
                label="原密码"
                placeholder="原密码"
                :rules="[{ required: true, message: '请填写原密码' }]"
        ></van-field>
        <van-field
                v-model="form.newpswd"
                type="password"
                name="新密码"
                label="新密码"
                placeholder="新密码"
                :rules="[{ required: true, message: '请填写新密码' }]"
        ></van-field>
        <div style="margin: 16px;">
            <van-button round block type="info" native-type="submit">提交</van-button>
        </div>
    </van-form>
    <br>
    <van-row><van-divider>退出登录</van-divider></van-row>
    <div style="margin: 16px;">
        <van-button round block type="danger" @click="logout">退出</van-button>
    </div>
    {include file="common/footer"/}
    <script>
        new Vue({
            el: '#app',
            data() {
                return {
                    user: {

                    },
                    active:"my",
                    form:{
                        oldpswd:"",
                        newpswd:"",

                    }
                }
            },
            mounted () {
                this.abcd();
            },
            methods: {
                abcd(){
                    var that = this;
                    axios.post('/admin/user/getmyvalue')
                        .then(function (response)
                        {
                            that.user = response.data.data;
                        })
                },
                onSubmit(){
                    var that = this;
                    axios.post('/admin/user/changepswd', Object.assign({}, PostBase, {
                        oldPassword: that.form.oldpswd,
                        newPassword: that.form.newpswd,
                    }))
                        .then(function (response) {
                            if (response.data.code == CODE_SUCCESS) {
                                alert('修改成功，跳转中')
                                setTimeout(function () {
                                    location.href='index';
                                }, 500);
                            } else {
                                that.$message.error(response.data.msg);
                            }
                        })
                        .catch(function (error) {
                            that.$message.error('服务器内部错误');
                            console.log(error);
                        });
                },
                logout() {
                    var that = this;
                    axios.post('/admin/user/logout')
                        .then(function (response)
                        {
                            if (response.data.code == 200) {
                                alert('退出成功，正在跳转中...')
                                setTimeout(function () {
                                    location.href='index';
                                }, 500)
                            } else {
                                that.$message.error(response.data.msg);
                            }
                        })
                        .catch(function (error)
                        {
                            that.$message.error('tuichu失败，服务器内部错误');
                        });
                },
            }
        })


    </script>

</html>